using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Sigecov.Models.Mapping
{
    public class UsuarioMap : EntityTypeConfiguration<Usuario>
    {
        public UsuarioMap()
        {
            // Primary Key
            this.HasKey(t => t.usuId);

            // Properties
            this.Property(t => t.usuLogin)
                .IsRequired()
                .HasMaxLength(40);

            this.Property(t => t.usuSenha)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.usuTipoAcesso)
                .IsRequired()
                .HasMaxLength(1);

            // Table & Column Mappings
            this.ToTable("Usuario");
            this.Property(t => t.usuId).HasColumnName("usuId");
            this.Property(t => t.funId).HasColumnName("funId");
            this.Property(t => t.usuLogin).HasColumnName("usuLogin");
            this.Property(t => t.usuSenha).HasColumnName("usuSenha");
            this.Property(t => t.usuTipoAcesso).HasColumnName("usuTipoAcesso");

            // Relationships
            this.HasRequired(t => t.Funcionario)
                .WithMany(t => t.Usuarios)
                .HasForeignKey(d => d.funId);

        }
    }
}
